import React, { useMemo } from 'react'
import { Link } from 'react-router-dom'

import { getUrlWithParams } from './WithRouter'

export const LinkWithParams = (props: any) => {
  const { to, ...rest } = props

  const memoTo = useMemo(() => {
    return getUrlWithParams(to)
  }, [to])

  return <Link to={memoTo} {...rest} />
}
